import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张宇田
 * Date: 2025-03-24
 * Time: 13:26
 */
public class Test {
    public static void main(String[] args) {
        Dijkstra dijkstra = new Dijkstra();
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入节点数和边数: ");
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        List<List<Edge>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) graph.add(new ArrayList<>());

        System.out.println("请输入每条边 (起点 终点 权重):");
        for (int i = 0; i < m; i++) {
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            int w = scanner.nextInt();
            graph.get(u).add(new Edge(v, w));
        }

        System.out.print("请输入源点: ");
        int source = scanner.nextInt();

        int[] result = dijkstra(n, graph, source);
        System.out.println("最短路径: " + Arrays.toString(result));
    }

    public static void main1(String[] args) {
        List<Drink> drinks = new ArrayList<>();
        drinks.add(new Drink("苏打水", 60, 600));
        drinks.add(new Drink("汽水", 10, 250));
        drinks.add(new Drink("橙汁", 36, 200));
        drinks.add(new Drink("苹果汁", 16, 100));
        drinks.add(new Drink("西瓜汁", 45, 300));

        // 根据单位价格降序排序
        Collections.sort(drinks, new DrinkComparator());

        int capacity = 800;
        double totalPrice = 0;
        List<String> selectedDrinks = new ArrayList<>();

        for (Drink drink : drinks) {
            if (capacity <= 0) {
                break;
            }

            // 饮品体积小于等于剩余容量，直接加入
            if (drink.volume <= capacity) {
                selectedDrinks.add(drink.name);
                totalPrice += drink.price;
                capacity -= drink.volume;
            } else {
                // 饮品体积大于剩余容量，部分加入
                // 使用剩余容量的比例来计算价格
                totalPrice += capacity * drink.unitPrice;
                capacity = 0; // 剩余容量已用完
            }
        }

        // 输出结果
        System.out.println("装入饮料组合：");
        for (String item : selectedDrinks) {
            System.out.println("  " + item);
        }
        System.out.printf("总价格：%.2f 元", totalPrice);
    }
}



























/*import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;


*//**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张宇田
 * Date: 2025-03-24
 * Time: 13:26
 *//*
public class Test {
    public static void main(String[] args) {
        List<Drink> drinks = new ArrayList<>();
        drinks.add(new Drink("苏打水",60,600));
        drinks.add(new Drink("汽水", 10, 250));
        drinks.add(new Drink("橙汁", 36, 200));
        drinks.add(new Drink("苹果汁", 16, 100));
        drinks.add(new Drink("西瓜汁", 45, 300));

        Collections.sort(drinks,new DrinkComparator());
        //System.out.println(drinks);

        int capacity = 800;
        double totalPrice = 0;
        List<String> selectedDrinks = new ArrayList<>();

        //容量小于0，结束，  饮料体积小于容量，放入饮料 ，钱++容量➖
        for(Drink drink : drinks){
            if(capacity <= 0){
                break;
            }
            //饮料体积小于总容量
            if(drink.volume <= capacity){
                selectedDrinks.add(drink.name);
                totalPrice += drink.price;
                capacity -= drink.volume;
            }else{
                //饮料体积大于总容量
                //剩余容量占饮料体积的比例
                int usedCapacity = drink.volume - capacity;
                totalPrice = totalPrice + usedCapacity *drink.unitPrice;
                capacity = 0;
            }
        }
        System.out.println("装入饮料组合：");
        for (String item : selectedDrinks) {
            System.out.println("  " + item);
        }
        System.out.printf("总价格：%.2f 元", totalPrice);
    }



}*/

